home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_17_1987_Transactor_Publishing.d64
/
mouse code.pal
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2023-02-26
|
3KB
|
101 lines
100 ;define variable labels
110 xpos .byt 0 ;save x position
120 ypos .byt 0 ;save y position
130 btns .byt 0 ;save btn status
140 ;
150 ;subroutine to read control port 2
160 rdport sei ;lock out keyboard
170 lda #$c0 ;
180 sta $dc02 ;set ddr to read
190 lda #$80 ;
200 sta $dc00 ;read control port 2
210 ldx #$00 ;allow time for
220 inx:bne *-1 ;lines to settle
230 ldx $d419 ;read pot x
240 ldy $d41a ;read pot y
250 lda #$ff ;
260 sta $dc00 ;reset port 2
270 rts ;
280 ;
290 ;subroutine for moving average al(NULL)rithm
300 avrg bcs avrgp ;if sign positive
310 avrgn eor #-1 ;if negative, do
320 adc #1 ;reverse subt
330 lsr ;allow half-weight
340 eor #-1 ;invert byte
350 clc ;to preserve sign
360 adc #1 ;
370 clc:rts ;
380 avrgp lsr ;allow half-weight
390 clc:rts ;to the byte
400 ;
410 ;main routine to read the stick
420 stick jsr rdport ;
430 lda $dc00 ;read port 2
440 and #$0c ;filter btn 1 & 2
450 eor #$ff ;invert logic
460 sta btns ;save btn1 & btn2
470 txa:sec ;store x in xpos
480 sbc xpos ;using a simple
490 jsr avrg ;moving average
500 adc xpos ;al(NULL)rithm
510 sta xpos ;update xpos
520 tya:sec ;store y in ypos
530 sbc ypos ;using the same
540 jsr avrg ;al(NULL)rithm
550 adc ypos ;and update ypos
560 sta ypos ;
570 ;
580 ;now test the buttons and exit
590 test ldx #$ff ;
600 stx $dc02 ;reset ddr
610 cli ;finished with port
620 lda #4 ;test bit 2
630 bit btns ;of btns
640 bne btn1 ;if btn1 pressed
650 asl ;test bit 3
660 bit btns ;of btns
670 bne btn2 ;if btn2 pressed
680 rts ;exit z=1 no btns
690 btn1 lda #-1 ;flag for btn1
700 .byt $2c ;skip over
710 btn2 lda #1 ;flag for btn2
720 rts ;exit z=0
730 ;
740 ;main routine to read the mouse
750 mouse jsr rdport ;
760 lda $dc00 ;read port 2
770 and #$10 ;filter btn1
780 sta btns ;save bit 4
790 txa ;read pot x
800 bmi low ;discern state
810 high lda #$20 ;set bit 5
820 .byt $2c ;skip over
830 low lda #$00 ;clr bit 5
840 ora btns ;combine bits 4 & 5
850 lsr:lsr ;shift to bits 2 & 3
860 eor #$ff ;invert logic
870 sta btns ;save btn1 & btn2
880 ;now we have our left and right buttons!
890 lda $dc00 ;read port 2
900 and #$0f ;filter directions
910 cmp #$0f ;"any movement ?
920 beq exit ;no, finish up
930 tax ;yes, mouse rolling
940 up [175] #1 ;check up
950 bne dn ;
960 inc y[185] ;
970 dn txa ;
980 [175] #2 ;check down
990 bne lft ;
1000 dec y[185] ;
1010 lft txa ;
1020 [175] #4 ;check left
1030 bne rht ;
1040 dec x[185] ;
1050 rht txa ;
1060 [175] #8 ;check right
1070 bne exit ;
1080 inc x[185] ;
1090 exit jmp test ;test but[164]n [175] exit